package com.pro.schedule.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pro.schedule.entity.EventType;
import com.pro.schedule.entity.EventTypeChild;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EventTypeChildMapper extends BaseMapper<EventTypeChild> {

    @Select("select * from event_type_child where event_type_id=#{eventTypeId}")
    List<EventTypeChild> getEventTypeChildList(Integer eventTypeId);

    @Select("select * from event_type_child where event_type_child_id=#{eventTypeChildId}")
    @Results(
            {
                    @Result(column = "event_type_child_id", property = "eventTypeChildId"),
                    @Result(column = "event_type_child_label", property = "eventTypeChildLabel"),
                    @Result(column = "target_id", property = "targetId"),
                    @Result(column = "event_type_id", property = "eventTypeId"),
                    @Result(column = "event_type_id", property = "eventType", javaType = EventType.class,
                            one = @One(select = "com.pro.schedule.mapper.EventTypeMapper.selectById")
                    )
            }
    )
    EventTypeChild getEventTypeChildInfo(Integer eventTypeChildId);

    @Delete("delete from event_type_child where event_type_id=#{eventTypeId}")
    void deleteEventTypeChildByEventTypeId(Integer eventTypeId);

    @Update("update event_type_child set target_id = NULL where target_id=#{targetId}")
    void clearEventTypeChildByTargetId(Integer targetId);

}
